<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{$Think.config.site.title} - 续费</title>
    <meta name="keywords" content="{$Think.config.site.keywords}">
    <meta name="description" content="{$Think.config.site.description}">
    <link href="{$Think.config.site.resource_url}css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/plugins/iCheck/custom.css" rel="stylesheet">
     <!-- Data Tables -->
    <link href="{$Think.config.site.resource_url}css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/animate.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/style.css?v=4.1.0" rel="stylesheet">
</head>
<body >
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                 <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <form action="" class="form-horizontal" method="post" id="myfoms">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">{:lang('是否重新选择版本')}</label>
                                <div class="col-sm-6"><input type="hidden" name="oid" value="{$v.oid}">
                                <input type="hidden" name="payable_amount" value="{$v.payable_amount}" id="payable_amount">
                                    <select data-placeholder="选择版本..." class="form-control chosen-select" id="version" name="version">
                                        <option value="">{:lang('请选择版本')}</option>
                                        {volist name="list" id="vo"}
                                        <option value="{$vo.id}" hassubinfo="true" {if condition="$vo['id'] eq $v['version']" } selected="selected" {/if}>{if condition="$vo['free'] eq 1"} {:lang('免费版')} {else / } {:lang('收费版')} {/if}{$vo.name}　{$vo.vision}　 {:lang('价格')}:{$vo.price}　</option>
                                        {/volist}   
                                    </select>
                                </div>
                                <div class="col-sm-4"><input type="hidden" name="banben" value="{$v.version}" id="banben">
                                    <br/>
                                    {:lang('当前版本')}:{$ver.name}　{:lang('版本号')}:{$ver.vision}  {if condition="$ver['free'] eq 1"} {:lang('免费版')} {else/} {:lang('收费版')}  {/if}
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">{:lang('输入金额')}</label>
                                <div class="col-sm-6">
                                    <input id="price" name="price" placeholder="{:lang('输入金额')}" required="required" class="form-control" type="text" value="{$v.real_amount}" >
                                </div>
                                <div class="col-sm-4">
                                    <input type="hidden" name="jine" value="{$v.real_amount}" id="jine">
                                </div>
                            </div>

                            <div class="hr-line-dashed"></div>
                            <div class="form-group" >
                                <label class="col-sm-2 control-label">{:lang('续费时长')}</label>
                                <div class="col-sm-6">
                                    <select class="form-control m-b __web-inspector-hide-shortcut__" id="times" name="endtime">
                                        <option value="">{:lang('请选择时长')}</option>
                                        <option value="1">1 {:lang('月')}</option>
                                        <option value="3">3 {:lang('月')}</option>
                                        <option value="6">6 {:lang('月')}</option>
                                        <option value="12">12 {:lang('月')}(1 {:lang('年')})</option>
                                        <option value="24">24 {:lang('月')}(2 {:lang('年')})</option>
                                        <option value="36">36 {:lang('月')}(3 {:lang('年')})</option>
                                        <option value="48">48 {:lang('月')}(4 {:lang('年')})</option>
                                        <option value="60">60 {:lang('月')}(5 {:lang('年')})</option>
                                    </select>
                                </div>
                                <?php  
                                    //时间加减
                                    
                                    $time = $v['old_expiration_date'] - time();
                                    $t = $time/(3600*24);
                                    if($t>0){
                                        $time = (floor($t));
                                    }else{
                                        $d= time()- $v['old_expiration_date'];
                                        $dtime = (floor($t));
                                    }
                                ?>
                                <div class="col-sm-4">{:lang('当前到期时间')}:{$v.old_expiration_date|date="Y-m-d",###} {if condition="$t gt 0"}　{:lang('距离到期时间还有')}<font style="font-size: 18px; color:red;">{$time}</font>{:lang('天')}{else /} <span style="color: red;font-size: 18px;">{:lang('已过期')} <font><?php echo abs($dtime);?></font>天</span>{/if}</div>
                            </div>
                            <input type="hidden" name="dq" value="{$v.old_expiration_date}">
                            <div class="hr-line-dashed"></div>
                            <h3 style="font-weight:100;">{:lang('总金额')}：<span id="totalAmount" style="color:#ff0000;">0</span> {:lang('元')}</h3>
                            <div class="hr-line-dashed"></div>
                            <div class="row"  style="margin-top: 23px;">
                                <div class="center-block col-sm-2">
                                    <button type="button" class="btn btn-primary btn-block" id="submit">{:lang('提交')} </button>
                                </div>      
                            </div>
                        </form>

                    </div>
                 </div>
            </div>
        </div>
    </div>
    <script src="{$Think.config.site.resource_url}js/jquery.min.js?v=2.1.4"></script>
    <script src="{$Think.config.site.resource_url}js/bootstrap.min.js?v=3.3.5"></script>
    <script src="{$Think.config.site.resource_url}js/content.min.js?v=1.0.0"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/validate/jquery.validate.min.js"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/validate/messages_zh.min.js"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/layer/layer.js"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/sweetalert/sweetalert.min.js"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/layer/laydate/laydate.js"></script>
    <script type="text/javascript">
        $(function(){
            $('#version').change(function(){
                var id = $(this).val();  //获取Select选择的Value
                //alert(checkValue);
                $.ajax({
                    type : 'GET',
                    url  : '<?php echo \think\Request::instance()->root(); ?>/ausadmin/Operator/add?id='+id,
                    dataType : 'json',
                    async : false,
                    success : function(result){
                        if(result){
                            $('#price').val(result.price);
                            $('#payable_amount').val(result.price);
                            $('#jine').val(result.price);
                            $('#banben').val(result.id);
                        }
                    },
                    
                })
            }); 
            $('#price').change(function(){
                var price = $(this).val();
                $('#jine').val(price);
            });
            $('#times').change(function(){
                var timenum = $('#times').val();
                var price = $('#price').val();
                var totalAmount = timenum * price;
                $('#totalAmount').html(totalAmount);
            });

            $('#submit').click(function(){
                var time = $('#times').val();
                var price = $('#price').val();
                var version = $('#version').val();
                if(price==''){
                    $('#price').focus();
                    layer.msg("{:lang('请正确输入有效金额')}", {icon: 5});
                    return false;
                }
                if(time==''){
                    $('#times').focus();
                    layer.msg("{:lang('请选择续费时长')}", {icon: 5});
                    return false;
                }
                if(version==''){
                    $('#version_chosen').focus();
                    layer.msg("{:lang('请选择版本')}", {icon: 5});
                    return false;
                }
                var formdata = $('#myfoms').serialize(); 
                $.ajax({
                    type : 'POST',
                    url  : '<?php echo \think\Request::instance()->root(); ?>/ausadmin/order/renew',
                    dataType : 'json',
                    data : formdata,
                    async : false,
                    success : function(result){
                        if(0 == result.code){
                            layer.msg(result.msg, {icon: 1});
                            parent.location.reload();
                        }else{
                            layer.msg(result.msg, {icon: 5});
                        }
                    },
                    error : function(){
                        layer.msg("{:lang('服务器错误！请稍后重试')}", {icon: 2});
                    }
                });
            }); 
        });
    </script>
</body>
</html>